package com.collection.admin.action;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.collection.common.base.BaseAction;
import com.collection.entity.SysAdmin;
import com.collection.service.SysAdminService;

/**
 * 后台管理员登录与注销控制类
 * @author 冯勇
 */
@Controller
@Scope("prototype")
public class AdminLoginAction extends BaseAction {

	private static final long serialVersionUID = -2305398973452729459L;
	
	@Autowired
	private SysAdminService sysAdminService;
	
	private SysAdmin admin;
	
	/**
	 * 登录
	 * @return
	 */
	public String login() {
		if(sysAdminService.login(admin)) {
			getSession().setAttribute("admin", admin.getUserName());
			return SUCCESS;
		} else {
			setMessage("账号或密码不正确！");
			return INPUT;
		}
	}
	
	/**
	 * 退出
	 * @return
	 */
	public String logout() {
		getSession().removeAttribute("admin");
		return SUCCESS;
	}

	public SysAdmin getAdmin() {
		return admin;
	}

	public void setAdmin(SysAdmin admin) {
		this.admin = admin;
	}
}
